<?php

class UserStatisticsController
{
    private $userStatisticsModel;
    private $diaryListModel;
    private $followModel;

    function __construct()/*{{{*/
    {
        $this->userStatisticsModel  =   new UserStatisticsModel();
        $this->diaryListModel       =   new DiaryListModel();
        $this->followModel          =   new FollowModel();
    }/*}}}*/

    public function userStatistics($info)/*{{{*/
    {
        if (empty($info['uid']) ||  count($info) <  2)
        {
            AC::$errorNo    =   'USC001';
            return  FALSE;
        }

        $result =   $this->userStatisticsModel->userStatistics($info);
        if (empty($result))
        {
            UK::varDump(AC::$errorNo, __METHOD__);
        }
        return  $result;
    }/*}}}*/

    public function getUserStatistics($info)/*{{{*/
    {
        if (empty($info['uid']))
        {
            AC::$errorNo    =   'USC002';
            return  FALSE;
        }

        $diary  =   $this->diaryListModel->countTotal($info);

        $info['secret'] =   1;
        $secret =   $this->diaryListModel->countTotal($info);

        $flag=0;
        if (!empty($info['status']) &&  (1  ==  $info['status']))  $flag=1;
        $info['type']   =   1;
        $info['status'] =   0;
        $fans   =   $this->followModel->countTotal($info);
        $info['type']   =   1;
        $info['status'] =   2;
        $blackMeTimes   =   $this->followModel->countTotal($info);
        $info['type']   =   2;
        $info['status'] =   0;
        $follow         =   $this->followModel->countTotal($info);
        $info['type']   =   2;
        $info['status'] =   2;
        $meBlackTimes   =   $this->followModel->countTotal($info);

        if ($flag)
        {
            $info['diaryTimes']         =   $diary;
            $info['secretDiaryTimes']   =   $secret;
            $info['followMeTimes']      =   $fans;
            $info['meFollowTimes']      =   $follow;
            $info['meBlackTimes']       =   $meBlackTimes;
            $info['blackMeTimes']       =   $blackMeTimes;
            $this->userStatisticsModel->setUserStatistics($info);
        }

        $user   =   $this->userStatisticsModel->getUserStatistics($info);
        $user['realDiary']      =   $diary;
        $user['secretDiary']    =   $secret;
        $user['realFans']       =   $fans;
        $user['realFollow']     =   $follow;

        return  $user;
    }/*}}}*/

}

